package com.ssm.controller;

import com.alibaba.fastjson.JSONObject;
import com.ssm.service.PackageService;
import com.ssm.unity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * Created by wtjr on 2018/1/9.
 */
@Controller
@RequestMapping("package")
public class PackageController {

    @Autowired
    PackageService service;

    @RequestMapping(value = "packageList", method = RequestMethod.POST)
    @ResponseBody
    /**
     * 根据商户id来获取他服务套餐列表
     */
    public JSONObject queryPackageList(String service_uuid, HttpServletRequest request) {
        ResponseResult result = new ResponseResult();
        result.setCurrentVersion();

        List list = service.queryPackageListByServiceId(service_uuid);
        if (list.isEmpty() || list == null) {
            result.setStatusCode("failure");
            result.setInvoking("0004");
            result.setMessage("该商家暂无可用套餐");
        } else {
            result.setStatusCode("success");
            result.setInvoking("0000");
            result.setMessage("登录成功");

            HashMap map = new HashMap();
            map.put("packageList", list);
            result.setDisposeResult(map);
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", result);
        return jsonObject;
    }
}
